diff --git a/django/db/models/query.py b/django/db/models/query.py
index d9c9b0db04..8fd63a2d87 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -690,7 +690,10 @@ class QuerySet:
         assert not self.query.is_sliced, \
             "Cannot use 'limit' or 'offset' with in_bulk"
         if field_name != 'pk' and not self.model._meta.get_field(field_name).unique:
-            raise ValueError("in_bulk()'s field_name must be a unique field but %r isn't." % field_name)
+            unique_constraints = [constraint for constraint in self.model._meta.constraints if isinstance(constraint, models.UniqueConstraint)]
+            unique_fields = set(chain.from_iterable(constraint.fields for constraint in unique_constraints))
+            if not (field.unique or field_name in unique_fields):
+                raise ValueError("in_bulk()'s field_name must be a unique field but %r isn't." % field_name)
         if id_list is not None:
             if not id_list:
                 return {}
